let path = require('path');
let HTMLWebPackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
    mode: "none",
    // entry: "./src/main-index.js",  // entry是一个字符串的情况适用于单页面应用 SPA 
    entry: {
        // entry也可以是一个对象 该对象属性名是打包之后的文件名字 属性值是打包的入口
        "bundle-index": "./src/main-index.js",
        "bundle-mine": "./src/main-mine.js"
    },
    output: {
        path: path.resolve(__dirname, "./dist"),
        // [name]表示占位符  将来这个name会被替换成 bundle-index  和  bundle-mine
        filename: "[name].js"
    },
    devtool: "source-map",
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    { loader: "style-loader" },
                    { loader: "css-loader" }
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    { loader: "style-loader" },
                    { loader: "css-loader" },
                    { loader: "sass-loader" },
                ]
            },
            // {
            //     test: /\.html$/,
            //     use: [
            //         { loader: "html-loader" }
            //     ]
            // },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            },
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: 'asset/resource',
                generator: {
                    filename: 'images1/[name][ext]'
                }
            },
        ]
    },
    plugins: [

        new CleanWebpackPlugin(),


        new HTMLWebPackPlugin({
            template: "./src/index.html",
            filename: "index.html",
            inject: "body",
            chunks: ['bundle-index']
        }),

        new HTMLWebPackPlugin({
            template: "./src/pages/mine.html",
            filename: "./pages/mine.html",
            inject: "body",
            chunks: ["bundle-mine"]
        }),

        new CopyPlugin({
            patterns: [
                {
                    from: "./src/images",
                    to: "./images"
                }
            ]
        }),

    
    ],
    devServer: {
        liveReload: true,
        hot: false,
        // 代理
        proxy: {
            // /guyun这一层的目的是为了把请求给过滤出来 也就是说 带着/guyun的需要被转发
            "/guyun": {
                target: "http://8.129.109.224:3000/",
                pathRewrite: { '^/guyun': '' },  // 但是真正的接口中是没有/guyun这一层的 所以需要再把路径里面的 /guyun 替换成空字符串
            }
        }
    },

}

